local sk__konghou = fk.CreateSkill {

  name = "sk__konghou",

  tags = {  },

}



sk__konghou:addEffect(fk.CardUsing, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(sk__konghou.name) and target ~= player and target.phase == Player.Play and not player:isNude() then
      local room = player.room
      local use_event = room.logic:getCurrentEvent():findParent(GameEvent.UseCard, true)
      if use_event == nil then return end
      local mark = target:getTableMark("sk__konghou_record-phase")
      if table.contains(mark, use_event.id) then
        return (#mark == 1 and mark[1] == use_event.id and data.card:isCommonTrick()) or
          (#mark == 2 and mark[2] == use_event.id and data.card.type == Card.TypeBasic)
      end
      if #mark > 1 then return end
      mark = {}
      room.logic:getEventsOfScope(GameEvent.UseCard, 2, function(e)
        local use = e.data
        if use.from == target then
          table.insert(mark, e.id)
          return true
        end
        return false
      end, Player.HistoryTurn)
      room:setPlayerMark(target, "sk__konghou_record-turn", mark)
      return (#mark == 1 and mark[1] == use_event.id and data.card:isCommonTrick()) or
        (#mark == 2 and mark[2] == use_event.id and data.card.type == Card.TypeBasic)
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local cards = room:askForDiscard(player, 1, 1, true, sk__konghou.name, true, ".",
      "#sk__konghou-invoke::"..target.id..":"..data.card:toLogString(), true)
    if #cards > 0 then
      event:setCostData(self, cards)
      room:doIndicate(player.id, {target.id})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:throwCard(event:getCostData(self) , sk__konghou.name, player, player)
    data:removeAllTargets()
    room:sendLog{
      type = "#CardNullifiedBySkill",
      from = target.id,
      arg = sk__konghou.name,
      arg2 = data.card:toLogString(),
    }
  end,
})

return sk__konghou